import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import '../../widgets/platform/adaptive_navigation.dart';
import 'users/user_management_page.dart';
import 'orgs/org_management_page.dart';
import 'roles/role_management_page.dart';
// 移除了对不存在的日志管理页面的导入
import 'monitoring/monitoring_page.dart';
// 导入新的笔记和知识图谱页面
import '../../pages/note/note_list_page.dart';
import '../../pages/knowledge/knowledge_graph_page.dart';
// 导入离线状态页面
import '../../pages/admin/offline/offline_status_page.dart';

/// 管理员仪表板页面
class AdminDashboardPage extends ConsumerStatefulWidget {
  const AdminDashboardPage({super.key});

  @override
  ConsumerState<AdminDashboardPage> createState() => _AdminDashboardPageState();
}

class _AdminDashboardPageState extends ConsumerState<AdminDashboardPage> {
  int _selectedIndex = 0;

  static final List<Widget> _pages = <Widget>[
    const UserManagementPage(),
    const OrgManagementPage(),
    const RoleManagementPage(),
    // 移除了对不存在的LogManagementPage的引用
    const MonitoringPage(),
    const NoteListPage(), // 添加笔记管理页面
    const KnowledgeGraphPage(), // 添加知识图谱页面
    const OfflineStatusPage(), // 添加离线状态页面
  ];

  static final List<NavigationDestination> _bottomDestinations =
      <NavigationDestination>[
    const NavigationDestination(
      icon: Icon(Icons.people),
      label: '用户管理',
    ),
    const NavigationDestination(
      icon: Icon(Icons.account_balance),
      label: '组织管理',
    ),
    const NavigationDestination(
      icon: Icon(Icons.security),
      label: '角色管理',
    ),
    // 移除了对不存在的日志管理的导航
    const NavigationDestination(
      icon: Icon(Icons.monitor),
      label: '系统监控',
    ),
    const NavigationDestination(
      // 添加笔记管理导航
      icon: Icon(Icons.note),
      label: '笔记管理',
    ),
    const NavigationDestination(
      // 添加知识图谱导航
      icon: Icon(Icons.hub),
      label: '知识图谱',
    ),
    const NavigationDestination(
      // 添加离线状态导航
      icon: Icon(Icons.offline_bolt),
      label: '离线状态',
    ),
  ];

  void _onItemTapped(int index) {
    setState(() {
      _selectedIndex = index;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const SelectableText('系统管理'),
        actions: [
          PopupMenuButton<String>(
            onSelected: (value) {
              switch (value) {
                case 'back':
                  context.pop();
                  break;
              }
            },
            itemBuilder: (context) => [
              PopupMenuItem(
                value: 'back',
                child: Row(
                  children: [
                    const Icon(Icons.arrow_back),
                    const SizedBox(width: 8),
                    const Text('返回'),
                  ],
                ),
              ),
            ],
          ),
        ],
      ),
      body: AdaptiveNavigation(
        selectedIndex: _selectedIndex,
        onDestinationSelected: _onItemTapped,
        destinations: _bottomDestinations,
        pages: _pages,
      ),
    );
  }
}
